package com.net.oil.main.adapter;
/*
 * Created by lch on 2018/2/21 0021.
 */

import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class ShopBannerViewPagerAdapter extends PagerAdapter {

    private List<View> viewList;

    public ShopBannerViewPagerAdapter(List<View> viewList){
        this.viewList = viewList;
    }

    @Override
    public int getCount() {
        return viewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = viewList.get(position % viewList.size());
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (position < viewList.size()){
            container.removeView(viewList.get(position % viewList.size()));
        }
    }
}
